package com.zjdiepu.www.proxy.impl;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.diepu.www.client.proxy.partner.request.divi.ApplyDiviProxyRequest;
import com.diepu.www.client.proxy.partner.request.divi.SynDiviAttachmentsRequest;
import com.zjdiepu.www.config.ClientConfig;
import com.zjdiepu.www.consts.ProxyService;
import com.zjdiepu.www.net.HttpClient;
import com.zjdiepu.www.proxy.IDiviService;
import com.zjdiepu.www.response.BooleanResponse;
import com.zjdiepu.www.security.base.enums.ResultCode;
import com.zjdiepu.www.security.client.encode.BaseEncryptService;
import com.zjdiepu.www.security.exception.BasePartnerException;
import com.zjdiepu.www.security.server.core.Partners;
/**
 * 
 * @author xiongxiaotun
 *
 */
@Service
public class DiviServiceService extends BaseEncryptService implements IDiviService {
	
	private Partners partner = Partners.HZ_ICBC;
	/**
	 * 申请分期接口
	 * @param request
	 * @return
	 * @throws BasePartnerException 
	 */
	public boolean applyDivi(ApplyDiviProxyRequest request) throws BasePartnerException {
		//签名
		String signEncrypt = signEncrypt(request, partner);
		if(StringUtils.isBlank(signEncrypt)) {
			throw new BasePartnerException(ResultCode.FAIL_PARAM_EMPTY);
		}
		String applyDiviJson = HttpClient.postJson(ClientConfig.getPartnerGateWay(partner) + ProxyService.DIEPU_APPLYDIVI, signEncrypt);
		BooleanResponse booleanResponse = valdateDencrypt(applyDiviJson, BooleanResponse.class, partner);
		return booleanResponse.getResult();
	}
	/**
	 * 补充分期资料
	 * @param request
	 * @return BasePartnerException
	 */
	public boolean postDiviAttachments(SynDiviAttachmentsRequest request) throws BasePartnerException {
		//签名
		String signEncrypt = signEncrypt(request, partner);
		if(StringUtils.isBlank(signEncrypt)) {
			throw new BasePartnerException(ResultCode.FAIL_PARAM_EMPTY);
		}
		String applyDiviJson = HttpClient.postJson(ClientConfig.getPartnerGateWay(partner) + ProxyService.DIEPU_SYN_DIVI_ATTACHMENTS, signEncrypt);
		BooleanResponse booleanResponse = valdateDencrypt(applyDiviJson, BooleanResponse.class, partner);
		return booleanResponse.getResult();
	}
}
